/*
 * @lc app=leetcode.cn id=98 lang=golang
 *
 * [98] 验证二叉搜索树
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */

var prev int = -1 << 31

func isValidBST(root *TreeNode) bool {
	return helper(root)
}

func helper(root *TreeNode) bool {
	if root == nil {
		return true
	}

	if helper(root.Left) {
		if root.Val > prev {
			prev = root.Val
			return helper(root.Right)
		}
	}
	return false
}

// @lc code=end

